﻿namespace MapleRock.P2PEmulator.RGR
{
  using System;
  using System.Collections.Generic;
  using System.Diagnostics;
  using System.Linq;
  using System.Text;

  public class ModelSampleParams
  {
    public static List<ModelSampleParams> GetSampleParams(
      int[] peersNumber,
      double[] messageLossProb,
      int[] dimensions,
      int[] maxPeerLinks,
      int variableParameterIndex,
      int peersNumberIndex,
      int messageLossProbIndex,
      int dimensionsIndex,
      int maxPeerLinksIndex)
    {
      Debug.Assert(variableParameterIndex >= 0, "variableParameterIndex >= 0");
      Debug.Assert(variableParameterIndex < 4, "variableParameterIndex < 4");

      var result = new List<ModelSampleParams>();

      switch(variableParameterIndex)
      {
        case 0:
          foreach (var pn in peersNumber)
          {
            var modelSampleParams = new ModelSampleParams();
            modelSampleParams.PeersNumber = pn;
            modelSampleParams.MessageLossProb = messageLossProb[messageLossProbIndex];
            modelSampleParams.Dimensions = dimensions[dimensionsIndex];
            modelSampleParams.MaxPeerLinks = maxPeerLinks[maxPeerLinksIndex];
            modelSampleParams.VariableParameter = pn;

            result.Add(modelSampleParams);
          }
          break;

        case 1:
          foreach (var pe in messageLossProb)
          {
            var modelSampleParams = new ModelSampleParams();
            modelSampleParams.PeersNumber = peersNumber[peersNumberIndex];
            modelSampleParams.MessageLossProb = pe;
            modelSampleParams.Dimensions = dimensions[dimensionsIndex];
            modelSampleParams.MaxPeerLinks = maxPeerLinks[maxPeerLinksIndex];
            modelSampleParams.VariableParameter = pe;

            result.Add(modelSampleParams);
          }
          break;

        case 2:
          foreach (var d in dimensions)
          {
            var modelSampleParams = new ModelSampleParams();
            modelSampleParams.PeersNumber = peersNumber[peersNumberIndex];
            modelSampleParams.MessageLossProb = messageLossProb[messageLossProbIndex];
            modelSampleParams.Dimensions = d;
            modelSampleParams.MaxPeerLinks = maxPeerLinks[maxPeerLinksIndex];
            modelSampleParams.VariableParameter = d;

            result.Add(modelSampleParams);
          }
          break;

        case 3:
          foreach (var v in maxPeerLinks)
          {
            var modelSampleParams = new ModelSampleParams();
            modelSampleParams.PeersNumber = peersNumber[peersNumberIndex];
            modelSampleParams.MessageLossProb = messageLossProb[messageLossProbIndex];
            modelSampleParams.Dimensions = dimensions[dimensionsIndex];
            modelSampleParams.MaxPeerLinks = v;
            modelSampleParams.VariableParameter = v;

            result.Add(modelSampleParams);
          }
          break;
      }

      return result;
    }

    public int PeersNumber { get; set; }

    public double MessageLossProb { get; set; }

    public int Dimensions { get; set; }

    public int MaxPeerLinks { get; set; }

    public double VariableParameter { get; set; }
  }
}
